(function (window, $, undefined) {
  'use strict';

  var logData = {};

  // 提取备注
  function remarkIt(data) {
    var mapData = {
      '/system/sys/user/sysUserlogin': '登录'
    };
    return mapData[data.interfaceName] || '';
  }

  main(function () {

    var $tableLog = $('#table-log');
    util.jqGrid($tableLog, {
      url: ajaxURL.SYSTEM + '/oaLog/getOaLogList',
      // datatype: 'json',
      autowidth: true,
      height: $(window).height() - 350,
      // multiselect: true,
      // multiboxonly: true,
      //shrinkToFit: false,
      colModel: [
        { name: 'kid', key: true, hidden: true },
        { label: '序号', name: 'kid', width: 50 },
        { label: '操作人', name: 'account', width: 100 },
        {
          label: '操作时间', name: 'createTime', width: 150, fixed: true, formatter: function (v, o, r) {
            return util.dateFormat(v);
          }
        },
        { label: '请求接口', name: 'interfaceName', width: 200 },
        { label: '请求参数', name: 'request', width: 300 },
        { label: '备注', name: 'remark', width: 100, formatter: function (v, o, r) {
          return remarkIt(r);
        } }
      ],
      pager: '#pager-log',
      loadComplete: function (res) {
        logData = {};
        if (res && res.data) {
          $.each(res.data, function (_, item) {
            logData[item.kid] = item;
          });
        }
      }
    });

    // 下单时间
    laydate.render({ elem: '#operateTime', range: '至' });

    function searchTable() {
      var data = util.formData('#form-search');

      var searchData = {
        operator: data.operator,
        title: data.title,
        timeBegin: '',
        timeEnd: ''
      };

      if (data.operateTime) {
        var temp = data.operateTime.split('至');
        searchData.timeBegin = util.getTime($.trim(temp[0]) + ' 00:00:00');
        searchData.timeEnd = util.getTime($.trim(temp[1]) + ' 23:59:59');
      }

      util.searchGrid($tableLog, searchData);
    }

    searchTable();
    $('#btn-search').click(searchTable);


  });


})(window, jQuery);
